<template>
  <div class="component-root-container">
    <el-header>
      <el-form ref="projectRule" :rules="projectRule" :model="project" label-width="120px" label-position="right">
        <el-row>
          <el-col :span="8">
            <el-form-item label="资产编码:" prop="assetCode">
                <el-input v-model="project['assetCode']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>

            <el-col :span="8">
            <el-form-item label="单位编码:" prop="orgCode">
                <el-input v-model="project['orgCode']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="站址编码:" prop="stationCode">
                <el-input v-model="project['stationCode']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" :offset="16" class="col_button">
              <div class="button">
                <el-button class="query" @click="buttonClick">
                  查询
                </el-button>
                <el-button class="query" @click="reset">
                  重置
                </el-button>
              </div>
            
          </el-col>
        </el-row>

      </el-form>
    </el-header>
    <el-main>
      <div class="contentInfo" style="margin-bottom:20px;">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景使用情况
          </el-col>
        </el-row>
        <el-row>
          <div class="inline">
            <div><span>调用次数/日：</span><span>{{ queryCount }}</span></div>
            <div><a class="link" href="javascript:;" @click="$router.push({name:'biz-ml'})">详情</a></div>
          </div>
        </el-row>
      </div>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景说明
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">根据入参单位编号、资产编号、站址编码，进行财务系统资产信息校验查询并返回校验结果。</div>
            
          </div>
          <div class="page-tip">
            <div class="params-tip"><span>示例参数</span>：资产编码:371300379214, 单位编码:371300, 站址编码:371300880000000000</div>
          </div>
        </el-row>
      </div>
    </el-main>
    <el-main>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            校验结果
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">
              <!-- <div> {{ dialog.title }} </div> -->
              <el-row v-for="(item,index) in dialog.content" :key="index" class="dialog-row">
                <el-col>
                  {{ item.checkMsg }}
                </el-col>
              </el-row>
            </div>
          </div>
        </el-row>
      </div>
    </el-main>

  </div>


</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        queryCount:0,
        project: {
            orgCode: '',
            assetCode: '',
            stationCode: ''
        },

        


        dialog: {
          title: '',
          content: []
        },
        options: [{
            value: 'tssai',
            key: '1'
          }
        ],
        projectRule: {
          codes: [{
            required: true,
            message: '请输入站址编码',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      this.queryPageCount('3.7');
    },
    mounted() {},
    computed: {},
    methods: {
      async buttonClick() {
        try {
          this.dialog = {
            title: '',
            content: []
          }

          await this.$refs['projectRule'].validate()
          const data = [{
            orgCode: this.project['orgCode'],
              assetCode: this.project['assetCode'],
              stationCode: this.project['stationCode']
          }]
          const datas = {
              datas: data
          }
          const r = await this.$http({
            url: this.$http.adornBizUrl('/assets/check'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify(datas), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          console.log(r.data);
          if (r.data.resultStat ==="000") {
            // console.log(r.data.data.retiurnMsg)
            this.dialog.content = r.data.data
            
            // this.dialog.title = r.data.data.retiurnMsg
          }else{
              this.dialog.title = r.data.mess
          }
          this.dialogVisible = true
        } catch (e) {
          console.log(e)
        } finally {
          this.listLoading = false
        }
      },
      getTitle(key) {
        const option = this.options.filter(o => o.key === key)
        let value = null
        if (option[0]) {
          value = option[0].value
        }
        return value
      },
      reset() {
        this.project = {
          prjCode: '',
          operationId: ''
        }

        this.dialog = {
          title: '',
          content: []
        }
        this.$refs['projectRule'].clearValidate();
      },
      change(e) {
        this.$forceUpdate()
      },

      async queryPageCount(scene) {
        try {
          const r = await this.$http({
            url: this.$http.adornBizUrl('/log/queryStatistics'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify({scene:scene}), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if(r.data.data && r.data.data.length >0){
              var result = r.data.data[0];
              this.queryCount=result.cnt||'0';
          }
        } catch (e) {
          console.log(e)
        } finally {
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../../../assets/scss/formatQueryPage";
  @include formatQueryPage(120px, 60%);
  .el-input, .el-select {
    width: 60%;
  }

  .query {
    color: rgba(255, 255, 255, 1);
    background: rgba(235, 75, 75, 1);
    border-radius: 6px;
    border-color: rgba(235, 75, 75, 1);
  }

  .custom-button {
    display: flex;
    justify-content: center;
  }

  .dialog-row {
    margin-bottom: 5px;
  }
</style>
